import { HttpClient } from '@angular/common/http';
import { Component, OnInit, OnDestroy } from '@angular/core';

import { MapService } from '../../core';

// apboxMapService
@Component({
  selector: 'app-mapbox-map',
  templateUrl: './mapbox-map.component.html',
  styleUrls: ['./mapbox-map.component.scss']
})
export class MapboxMapComponent implements OnInit, OnDestroy {
  mapboxmap = null;
  constructor(
    private http: HttpClient,
    private mapService: MapService,
  ) { }
  ngOnInit() {
    // 地图初始化添加水印
    // this.addWaterMark();
    console.log("MapboxMapComponent ngOnInit()")
    this.mapService.init().then((res) => {
      console.log("MapboxMapComponent ngOnInit()", res)
      this.mapboxmap = res;
      console.log('地图创建完成');
      this.mapboxmap.on('load', () => {
        console.log('样式加载完成');
        this.mapService.addSpGroupLayer();
        this.mapService.loadIcons();
      });
    });
  }
  ngOnDestroy() {
    this.mapService.glmap = null;
    this.mapService.spStyle = null;
  }
}
